{% extends 'console.html' %}

{% block maincontent %}
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <!-- 搜索表单 -->
                <form class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="task_name" class="layui-input" lay-affix="clear">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">数据源名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="connect_name" class="layui-input" lay-affix="clear">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                            </button>
                            <button class="layui-btn layui-btn-primary layuiadmin-btn-list" type="reset">
                                <i class="layui-icon layui-icon-set-sm layuiadmin-button-btn"></i>重置
                            </button>
                            <button class="layui-btn layui-btn-normal layuiadmin-btn-list" type="button" id="addBtn">
                                <i class="layui-icon layui-icon-add-circle-fine layuiadmin-button-btn"></i>添加
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <!-- 数据表格 -->
                <table id="compareTaskTable" lay-filter="compareTaskTable"></table>
            </div>
        </div>
    </div>

{% endblock %}


{% block script %}
    <!-- 添加/编辑表单弹窗 -->
    <script type="text/html" id="formDialog">
        <!--<div class="layui-container" style="width:1300px;">-->
        <form class="layui-form" lay-filter="compareTaskAddOrEditForm" style="padding:20px">
            <input type="hidden" id="comp_task_id" name="comp_task_id">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">任务名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="comp_task_name" id="comp_task_name" required lay-verify="required"
                               placeholder="比对任务名称" class="layui-input"
                               style="width:300px;">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据源1<br>
                        <div style="color: red;">（基线）</div>
                    </label>
                    <div class="layui-input-inline">
                        <!--<select name="category" lay-verify="required">-->
                        <label>
                            <select id="dataSource1" name="dataSource1" lay-verify="required" lay-search>
                                <option value="">直接或搜索选择（必填）</option>

                                <!--{% for dbsource in dbsources %}
                            <option value="{{ dbsource['db_cfg_id'] }}">{{ dbsource['connect_name'] }}</option>
                            {% endfor %}-->

                            </select>
                        </label>
                    </div>
                    <label class="layui-form-label">数据源2</label>
                    <div class="layui-input-inline">
                        <label>
                            <select id="dataSource2" name="dataSource2" lay-verify="required" lay-search>
                                <option value="">直接或搜索选择（必填）</option>
                            </select>
                        </label>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据源3</label>
                    <div class="layui-input-inline">
                        <select id="dataSource3" name="dataSource3" lay-search>
                            <option value="">直接或搜索选择</option>
                        </select>
                    </div>
                    <label class="layui-form-label">数据源4</label>
                    <div class="layui-input-inline">
                        <select id="dataSource4" name="dataSource4" lay-search>
                            <option value="">直接或搜索选择</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据源5</label>
                    <div class="layui-input-inline">
                        <select id="dataSource5" name="dataSource5" lay-search>
                            <option value="">直接或搜索选择</option>
                        </select>
                    </div>
                    <label class="layui-form-label">数据源6</label>
                    <div class="layui-input-inline">
                        <select id="dataSource6" name="dataSource6" lay-search>
                            <option value="">直接或搜索选择</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据源7</label>
                    <div class="layui-input-inline">
                        <select id="dataSource7" name="dataSource7" lay-search>
                            <option value="">直接或搜索选择</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <div class="layui-inline">
                    <label class="layui-form-label">描述或备注</label>
                    <div class="layui-input-block">
                    <textarea id="comment" name="comment" placeholder="请输入你想描述或备注的比对任务的相关信息(非必填)"
                              class="layui-textarea" style="width:500px;"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="submitBtn" lay-submit lay-filter="formSubmit">提交</button>
                    <button type="button" class="layui-btn" id="closeWindowsBtn">关闭</button>
                </div>
            </div>
        </form>
        <!--</div>-->
    </script>

    <!-- 操作列模板 -->
    <script type="text/html" id="operateTpl">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="more">
            更多
            <i class="layui-icon layui-icon-down"></i>
        </a>
        {#<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>#}
    </script>

    <script>
        layui.use(['table', 'form', 'layer', 'dropdown'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            var dropdown = layui.dropdown;

            function initDropDownListBoxData() {
                // 初始化时加载下拉框数据
                $.ajax({
                    url: '/dcs/api/getConnectNames',
                    type: 'GET',
                    dataType: 'json',
                    success: function (res) {
                        if (res.code === 0) {
                            var html = '<option value="">直接或搜索选择（必填）</option>';
                            $.each(res.data, function (index, item) {
                                html += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                            });
                            $('#dataSource1').html(html);
                            $('#dataSource2').html(html);
                            html = '<option value="">直接或搜索选择</option>';
                            $.each(res.data, function (index, item) {
                                html += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                            });
                            $('#dataSource3').html(html);
                            $('#dataSource4').html(html);
                            $('#dataSource5').html(html);
                            $('#dataSource6').html(html);
                            $('#dataSource7').html(html);
                            // 重新渲染表单
                            form.render('select');
                        }
                    },
                    error: function () {
                        layer.msg('数据加载失败');
                    }
                });
            }

            // 初始化表格
            var tableIns = table.render({
                elem: '#compareTaskTable',
                url: '/dcs/api/compareTasks',
                method: 'get',
                page: true,
                // height: 600,
                cols: [[
                    {field: 'comp_task_id', title: 'ID', width: 80, align: 'center', fixed: 'left',},
                    {
                        field: 'comp_task_name',
                        title: '任务名称',
                        width: 230,
                        align: 'left',
                        fixed: 'left',
                        templet: addlink,
                        sort: true
                    },
                    {field: 'connect_name1', title: '数据源1名称', width: 200, align: 'left'},
                    {field: 'connect_name2', title: '数据源2名称', width: 200, align: 'left'},
                    {field: 'connect_name3', title: '数据源3名称', width: 200, align: 'left'},
                    {field: 'connect_name4', title: '数据源4名称', width: 200, align: 'left'},
                    {field: 'connect_name5', title: '数据源5名称', width: 200, align: 'left'},
                    {field: 'connect_name6', title: '数据源6名称', width: 200, align: 'left'},
                    {field: 'connect_name7', title: '数据源7名称', width: 200, align: 'left'},
                    {field: 'last_update_date', title: '最后更新时间', width: 180, align: 'left'},
                    {field: 'comment', title: '描述', width: 280, align: 'left'},
                    {fixed: 'right', title: '操作', width: 134, minWidth: 150, toolbar: '#operateTpl'}
                ]]
            });

            // 搜索表单提交
            form.on('submit(search)', function (data) {
                tableIns.reload({
                    where: data.field,
                    page: {curr: 1}
                });
                return false;
            });

            // 添加按钮事件
            $('#addBtn').click(function () {
                initDropDownListBoxData();
                var index = layer.open({
                    type: 1,
                    title: '添加比对任务',
                    area: '700px',
                    content: $('#formDialog').html()
                });
                form.render();
                // 关闭窗口按钮
                $('#closeWindowsBtn').click(function () {
                    layer.close(index); // 关闭加载层
                });

                // 表单提交事件
                form.on('submit(formSubmit)', function (data) {
                    // alert("JSON.stringify(data.field)=" + JSON.stringify(data.field))
                    // alert("data.field.comp_task_id = " + data.field.comp_task_id)
                    var method = data.field.comp_task_id ? 'PUT' : 'POST';
                    var url = data.field.comp_task_id ? '/dcs/api/compareTask/' + data.field.comp_task_id : '/dcs/api/compareTask';
                    $.ajax({
                        url: url,
                        type: method,
                        contentType: 'application/json',
                        data: JSON.stringify(data.field),
                        success: function () {
                            layer.closeAll();
                            layer.msg('操作成功');
                            tableIns.reload();
                        },
                        error: function (xhr) {
                            layer.msg('操作失败: ' + xhr.responseJSON.msg);
                        }
                    });
                    return false;
                });
            });

            // 表格操作事件 触发单元格工具事件
            table.on('tool(compareTaskTable)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'edit') {
                        // alert("data.comp_task_id=" + data.comp_task_id)
                        // 初始化时加载下拉框数据
                        $.ajax({
                            url: '/dcs/api/getConnectNames',
                            type: 'GET',
                            dataType: 'json',
                            success: function (res) {
                                if (res.code === 0) {
                                    var html1 = '<option value="">直接或搜索选择（必填）</option>';
                                    var html2 = '<option value="">直接或搜索选择（必填）</option>';
                                    var html3 = '<option value="">直接或搜索选择</option>';
                                    var html4 = '<option value="">直接或搜索选择</option>';
                                    var html5 = '<option value="">直接或搜索选择</option>';
                                    var html6 = '<option value="">直接或搜索选择</option>';
                                    var html7 = '<option value="">直接或搜索选择</option>';
                                    $.each(res.data, function (index, item) {
                                        // alert("item.db_info_id=" + item.db_info_id + ", data.db_info_1_id=" + data.db_info_1_id)
                                        // console.log("item.db_info_id=" + item.db_info_id + ", data.db_info_1_id=" + data.db_info_1_id);
                                        if (item.db_info_id === data.db_info_1_id) {
                                            html1 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html1 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_2_id) {
                                            html2 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html2 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_3_id) {
                                            html3 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html3 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_4_id) {
                                            html4 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html4 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_5_id) {
                                            html5 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html5 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_6_id) {
                                            html6 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html6 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }

                                        if (item.db_info_id === data.db_info_7_id) {
                                            html7 += '<option value="' + item.db_info_id + '" selected>' + item.connect_name + '</option>';
                                        } else {
                                            html7 += '<option value="' + item.db_info_id + '">' + item.connect_name + '</option>';
                                        }
                                    });
                                    $('#dataSource1').html(html1);
                                    $('#dataSource2').html(html2);
                                    $('#dataSource3').html(html3);
                                    $('#dataSource4').html(html4);
                                    $('#dataSource5').html(html5);
                                    $('#dataSource6').html(html6);
                                    $('#dataSource7').html(html7);
                                    $("#comp_task_name").val(data.comp_task_name);
                                    $("#comment").html(data.comment);
                                    $("#comp_task_id").val(data.comp_task_id);
                                    // 重新渲染表单
                                    form.render('select');
                                }
                            },
                            error: function () {
                                layer.msg('数据加载失败');
                            }
                        });
                        var index = layer.open({
                            type: 1,
                            title: '编辑比对任务',
                            area: '700px',
                            content: $('#formDialog').html(),
                            success: function () {
                            }
                        });
                        // form.render();

                        // 关闭窗口按钮
                        $('#closeWindowsBtn').click(function () {
                            layer.close(index); // 关闭加载层
                        });

                        // 表单提交事件
                        form.on('submit(formSubmit)', function (data) {
                            // alert("JSON.stringify(data.field)=" + JSON.stringify(data.field))
                            // alert("data.field.comp_task_id = " + data.field.comp_task_id)
                            var method = data.field.comp_task_id ? 'PUT' : 'POST';
                            var url = data.field.comp_task_id ? '/dcs/api/compareTask/' + data.field.comp_task_id : '/dcs/api/compareTask';
                            $.ajax({
                                url: url,
                                type: method,
                                contentType: 'application/json',
                                data: JSON.stringify(data.field),
                                success: function () {
                                    layer.closeAll();
                                    layer.msg('操作成功');
                                    tableIns.reload();
                                },
                                error: function (xhr) {
                                    layer.msg('操作失败: ' + xhr.responseJSON.msg);
                                }
                            });
                            return false;
                        });
                    } else if (obj.event === 'more') {
                        // 更多 - 下拉菜单
                        dropdown.render({
                            elem: this, // 触发事件的 DOM 对象
                            show: true, // 外部事件触发即显示
                            data: [{
                                title: '查看',
                                id: 'detail'
                            }, {
                                title: '生成【模型字段比对】信息',
                                id: 'executeCompareTableJobResult'
                            }, {
                                title: '生成【模型比对修复】脚本',
                                id: 'executeJobTableRepare'
                            }, {
                                title: '生成【模型字段比对修复】脚本',
                                id: 'executeJobTableColumnRepare'
                            }, {
                                title: '删除',
                                id: 'del'
                            }],
                            click: function (menudata) {
                                if (menudata.id === 'detail') {
                                    detailShowForm(data);
                                } else if (menudata.id === 'executeCompareTableJobResult') {
                                    // 生成【模型比对修复】结果
                                    var loadIndex = layer.load(2);
                                    $.ajax({
                                        url: '/dcs/api/initCompareTableJobResult/' + data.comp_task_id,
                                        type: 'GET',
                                        contentType: "json",
                                        data: { // 提交数据
                                            // "databaseSourceDataOfForm": databaseSourceDataOfFormJson
                                        },
                                        success: function (data) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // alert(data);
                                            // const returnDataJson = JSON.stringify(data);
                                            // alert("returnDataJson = " + returnDataJson);
                                            // alert("data.msg = " + data.msg);
                                            if (data.code === 1) {
                                                layer.alert('生成【模型比对修复】结果，成功！', {
                                                    icon: 1,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else if (data.code === 0) {
                                                layer.alert('生成【模型比对修复】结果，失败！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else {
                                                layer.alert('未知错误！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            }
                                        },
                                        error: function (xhr, status, error) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // 基础错误信息
                                            var errorMsg = "请求失败: " + status + "<br>错误码: " + xhr.status;
                                            // 尝试解析服务器返回的详细错误信息
                                            try {
                                                var response = JSON.parse(xhr.responseText);
                                                alert("response = " + response)
                                                if (response.message) errorMsg += "<br>消息: " + response.message;
                                                if (response.error) errorMsg += "<br>错误详情: " + response.error;
                                                if (response.msg) errorMsg += "<br>错误详情: " + response.msg;
                                            } catch (e) {
                                                errorMsg += "<br>响应原始数据: " + xhr.responseText;
                                            }
                                            // 控制台打印完整错误对象
                                            console.error("完整错误对象:", xhr);
                                            // 弹窗显示详细错误（使用 Layui 的 layer）
                                            layer.open({
                                                type: 1,
                                                title: '请求错误详情',
                                                area: ['500px', '300px'],
                                                content: '<div class="layui-padding">' + errorMsg + '</div>'
                                            });
                                        }
                                    });
                                } else if (menudata.id === 'executeJobTableRepare') {
                                    // 生成【模型详情比对修复】结果
                                    var loadIndex = layer.load(2);
                                    $.ajax({
                                        url: '/dcs/api/initJobTableRepare/' + data.comp_task_id,
                                        type: 'GET',
                                        contentType: "json",
                                        data: { // 提交数据
                                            // "databaseSourceDataOfForm": databaseSourceDataOfFormJson
                                        },
                                        success: function (data) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // alert(data);
                                            // const returnDataJson = JSON.stringify(data);
                                            // alert("returnDataJson = " + returnDataJson);
                                            // alert("data.msg = " + data.msg);
                                            if (data.code === 1) {
                                                layer.alert('生成【模型详情比对修复】结果，成功！', {
                                                    icon: 1,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else if (data.code === 0) {
                                                layer.alert('生成【模型详情比对修复】结果，失败！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else {
                                                layer.alert('未知错误！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            }
                                        },
                                        error: function (xhr, status, error) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // 基础错误信息
                                            var errorMsg = "请求失败: " + status + "<br>错误码: " + xhr.status;
                                            // 尝试解析服务器返回的详细错误信息
                                            try {
                                                var response = JSON.parse(xhr.responseText);
                                                alert("response = " + response)
                                                if (response.message) errorMsg += "<br>消息: " + response.message;
                                                if (response.error) errorMsg += "<br>错误详情: " + response.error;
                                                if (response.msg) errorMsg += "<br>错误详情: " + response.msg;
                                            } catch (e) {
                                                errorMsg += "<br>响应原始数据: " + xhr.responseText;
                                            }
                                            // 控制台打印完整错误对象
                                            console.error("完整错误对象:", xhr);
                                            // 弹窗显示详细错误（使用 Layui 的 layer）
                                            layer.open({
                                                type: 1,
                                                title: '请求错误详情',
                                                area: ['500px', '300px'],
                                                content: '<div class="layui-padding">' + errorMsg + '</div>'
                                            });
                                        }
                                    });
                                } else if (menudata.id === 'executeJobTableColumnRepare') {
                                    // 生成【模型字段比对及修复】脚本
                                    var loadIndex = layer.load(2);
                                    $.ajax({
                                        url: '/dcs/api/initJobTableColumnRepare/' + data.comp_task_id,
                                        type: 'GET',
                                        contentType: "json",
                                        data: { // 提交数据
                                            // "databaseSourceDataOfForm": databaseSourceDataOfFormJson
                                        },
                                        success: function (data) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // alert(data);
                                            // const returnDataJson = JSON.stringify(data);
                                            // alert("returnDataJson = " + returnDataJson);
                                            // alert("data.msg = " + data.msg);
                                            if (data.code === 1) {
                                                layer.alert('生成【模型字段比对及修复】脚本，成功！', {
                                                    icon: 1,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else if (data.code === 0) {
                                                layer.alert('生成【模型字段比对及修复】脚本，失败！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            } else {
                                                layer.alert('未知错误！' + data.msg, {
                                                    icon: 2,
                                                    shadeClose: true,
                                                    title: '提示'
                                                });
                                            }
                                        },
                                        error: function (xhr, status, error) {
                                            layer.close(loadIndex); // 关闭加载层
                                            // 基础错误信息
                                            var errorMsg = "请求失败: " + status + "<br>错误码: " + xhr.status;
                                            // 尝试解析服务器返回的详细错误信息
                                            try {
                                                var response = JSON.parse(xhr.responseText);
                                                alert("response = " + response)
                                                if (response.message) errorMsg += "<br>消息: " + response.message;
                                                if (response.error) errorMsg += "<br>错误详情: " + response.error;
                                                if (response.msg) errorMsg += "<br>错误详情: " + response.msg;
                                            } catch (e) {
                                                errorMsg += "<br>响应原始数据: " + xhr.responseText;
                                            }
                                            // 控制台打印完整错误对象
                                            console.error("完整错误对象:", xhr);
                                            // 弹窗显示详细错误（使用 Layui 的 layer）
                                            layer.open({
                                                type: 1,
                                                title: '请求错误详情',
                                                area: ['500px', '300px'],
                                                content: '<div class="layui-padding">' + errorMsg + '</div>'
                                            });
                                        }
                                    });
                                } else if (menudata.id === 'del') {
                                    layer.confirm('确定删除吗？', function (index) {
                                        $.ajax({
                                            url: '/dcs/api/compareTask/' + data.comp_task_id,
                                            type: 'DELETE',
                                            success: function () {
                                                layer.close(index);
                                                tableIns.reload();
                                            }
                                        });
                                    });
                                }
                            },
                            align: 'right', // 右对齐弹出
                            style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' // 设置额外样式
                        });
                    } else if (obj.event === 'infoDetail') {
                        detailShowForm(data);
                    }
                }
            )
            ;

            function isFieldEmpty(value) {
                return value === null || value === undefined || value === "" || Number.isNaN(value);
            }

            function addlink(d) {
                var html = '<div><a rel="nofollow" style="color:#1E9FFF" href="javascript:void(0);" lay-event="infoDetail">'
                    + d.comp_task_name + '</a></div>';
                return html
            }

            // 查看数据详情
            function detailShowForm(data) {
                var title = '查看比对任务';
                var index = layer.open({
                    type: 1,
                    title: title,
                    content: $('#formDialog').html(),
                    // area: ['550px', '650px'],
                    area: '700px',
                    success: function () {
                        form.val('compareTaskAddOrEditForm', data);
                        // 禁用文本框
                        $("#comp_task_name").attr("disabled", true);

                        // 禁用选择框
                        var html = '<option value="' + data.db_info_1_id + '" selected disabled>' + data.connect_name1 + '</option>';
                        $('#dataSource1').html(html);
                        $("#dataSource1").attr("disabled", true);
                        // 禁用选择框
                        html = '<option value="' + data.db_info_2_id + '" selected disabled>' + data.connect_name2 + '</option>';
                        $('#dataSource2').html(html);
                        $("#dataSource2").attr("disabled", true);

                        // 禁用选择框
                        var html3 = "";
                        if (isFieldEmpty(data.db_info_3_id) === true) {
                            html3 = '<option value="" selected disabled>未配置</option>';
                        } else {
                            html3 = '<option value="' + data.db_info_3_id + '" selected disabled>' + data.connect_name3 + '</option>';
                        }
                        $('#dataSource3').html(html3);
                        $("#dataSource3").attr("disabled", true);

                        var html4 = "";
                        if (isFieldEmpty(data.db_info_4_id) === true) {
                            html4 = '<option value="" selected disabled>未配置</option>';
                        } else {
                            html4 = '<option value="' + data.db_info_4_id + '" selected disabled>' + data.connect_name4 + '</option>';
                        }
                        $('#dataSource4').html(html4);
                        $("#dataSource4").attr("disabled", true);

                        var html5 = "";
                        if (isFieldEmpty(data.db_info_5_id) === true) {
                            html5 = '<option value="" selected disabled>未配置</option>';
                        } else {
                            html5 = '<option value="' + data.db_info_5_id + '" selected disabled>' + data.connect_name5 + '</option>';
                        }
                        $('#dataSource5').html(html5);
                        $("#dataSource5").attr("disabled", true);

                        var html6 = "";
                        if (isFieldEmpty(data.db_info_6_id) === true) {
                            html6 = '<option value="" selected disabled>未配置</option>';
                        } else {
                            html6 = '<option value="' + data.db_info_6_id + '" selected disabled>' + data.connect_name6 + '</option>';
                        }
                        $('#dataSource6').html(html6);
                        $("#dataSource6").attr("disabled", true);

                        var html7 = "";
                        if (isFieldEmpty(data.db_info_7_id) === true) {
                            html7 = '<option value="" selected disabled>未配置</option>';
                        } else {
                            html7 = '<option value="' + data.db_info_7_id + '" selected disabled>' + data.connect_name7 + '</option>';
                        }
                        $('#dataSource7').html(html7);
                        $("#dataSource7").attr("disabled", true);
                        // 禁用文本框
                        $("#comment").attr("disabled", true).attr("placeholder", "未填写");

                        // 禁用按钮
                        $("#submitBtn").attr("disabled", true).addClass("layui-btn-disabled");
                        // 重新渲染表单
                        form.render('select');
                    }
                });
                // 关闭窗口按钮
                $('#closeWindowsBtn').click(function () {
                    layer.close(index); // 关闭加载层
                });
            }

        });


    </script>

{% endblock %}